package com.photologics.main;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.photologics.logic.LogicHelper;

public class ShopDialog extends Dialog implements OnClickListener {
	private LinearLayout itemHorizontal;
	private LinearLayout itemVertical;
	private LinearLayout itemSquar;
	private LinearLayout itemShowImage;
	private LinearLayout itemRemoveX;
	public static TextView countItemHorizontal;
	public static TextView countItemVertical;
	public static TextView countItemSquar;
	public static TextView countItemShowImage;
	public static TextView countItemRemoveX;
	public static TextView countCoin;
	Context mcontext;

	public ShopDialog(Context context) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.shop_dialog);

		mcontext = context;
		itemHorizontal = (LinearLayout) findViewById(R.id.item_horizontal);
		itemVertical = (LinearLayout) findViewById(R.id.item_vertical);
		itemSquar = (LinearLayout) findViewById(R.id.item_squar);
		itemShowImage = (LinearLayout) findViewById(R.id.item_showimage);
		itemRemoveX = (LinearLayout) findViewById(R.id.item_removex);

		itemHorizontal.setOnClickListener(this);
		itemVertical.setOnClickListener(this);
		itemSquar.setOnClickListener(this);
		itemShowImage.setOnClickListener(this);
		itemRemoveX.setOnClickListener(this);

		countItemHorizontal = (TextView) findViewById(R.id.textitem_horizontal);
		countItemVertical = (TextView) findViewById(R.id.textitem_vertical);
		countItemSquar = (TextView) findViewById(R.id.textitem_squar);
		countItemShowImage = (TextView) findViewById(R.id.textitem_showimage);
		countItemRemoveX = (TextView) findViewById(R.id.textitem_removex);

		countCoin = (TextView) findViewById(R.id.textshop_coin);

		countItemHorizontal.setText("보유개수 :"
				+ LogicHelper.accountInfo.getHorizontal());
		countItemVertical.setText("보유개수 :"
				+ LogicHelper.accountInfo.getVertical());
		countItemSquar.setText("보유개수 :" + LogicHelper.accountInfo.getSquar());
		countItemShowImage.setText("보유개수 :"
				+ LogicHelper.accountInfo.getShowImage());
		countItemRemoveX.setText("보유개수 :"
				+ LogicHelper.accountInfo.getRemoveX());

		countCoin.setText(LogicHelper.accountInfo.getCoin() + " ");

	}

	@Override
	public void onClick(View v) {
		v.invalidate();
		if (v == itemHorizontal) {
			if (LogicHelper.accountInfo.getCoin() < 500) {
				Toast.makeText(mcontext, "코인이 모자랍니다", Toast.LENGTH_SHORT)
						.show();
			} else {

				ShopItemSelectDialog shopslelectdialog = new ShopItemSelectDialog(
						mcontext, "itemHorizontal", 500);
				shopslelectdialog.show();

			}
		} else if (v == itemVertical) {
			if (LogicHelper.accountInfo.getCoin() < 500) {
				Toast.makeText(mcontext, "코인이 모자랍니다", Toast.LENGTH_SHORT)
						.show();
			} else {

				ShopItemSelectDialog shopslelectdialog = new ShopItemSelectDialog(
						mcontext, "itemVertical", 500);
				shopslelectdialog.show();

			}
		} else if (v == itemSquar) {
			if (LogicHelper.accountInfo.getCoin() < 1000) {
				Toast.makeText(mcontext, "코인이 모자랍니다", Toast.LENGTH_SHORT)
						.show();
			} else {

				ShopItemSelectDialog shopslelectdialog = new ShopItemSelectDialog(
						mcontext, "itemSquar", 1000);
				shopslelectdialog.show();

			}
		} else if (v == itemShowImage) {
			if (LogicHelper.accountInfo.getCoin() < 1500) {
				Toast.makeText(mcontext, "코인이 모자랍니다", Toast.LENGTH_SHORT)
						.show();
			} else {

				ShopItemSelectDialog shopslelectdialog = new ShopItemSelectDialog(
						mcontext, "itemShowImage", 1500);
				shopslelectdialog.show();

			}
		} else if (v == itemRemoveX) {
			if (LogicHelper.accountInfo.getCoin() < 2000) {
				Toast.makeText(mcontext, "코인이 모자랍니다", Toast.LENGTH_SHORT)
						.show();
			} else {

				ShopItemSelectDialog shopslelectdialog = new ShopItemSelectDialog(
						mcontext, "itemRemoveX", 2000);
				shopslelectdialog.show();

				countCoin.setText(LogicHelper.accountInfo.getCoin() + "원");
				countItemRemoveX.setText("보유개수 :"
						+ LogicHelper.accountInfo.getRemoveX());
			}
		}
	}

}
